var e = require;
var t = module;
var n = exports;
var i =
    (this && this.__awaiter) ||
    function(e, a, s, c) {
        return new(s = s || Promise)(function(n, t) {
            function o(e) {
                try {
                    r(c.next(e));
                } catch (e) {
                    t(e);
                }
            }

            function i(e) {
                try {
                    r(c.throw(e));
                } catch (e) {
                    t(e);
                }
            }

            function r(e) {
                var t;
                e.done ?
                    n(e.value) :
                    ((t = e.value) instanceof s ?
                        t :
                        new s(function(e) {
                            e(t);
                        })
                    ).then(o, i);
            }
            r((c = c.apply(e, a || [])).next());
        });
    },
    l =
    (this && this.__generator) ||
    function(n, o) {
        var i,
            r,
            a,
            s = {
                label: 0,
                sent: function() {
                    if (1 & a[0]) throw a[1];
                    return a[1];
                },
                trys: [],
                ops: []
            },
            e = { next: t(0), throw: t(1), return: t(2) };
        return (
            "function" == typeof Symbol &&
            (e[Symbol.iterator] = function() {
                return this;
            }),
            e
        );

        function t(t) {
            return function(e) {
                return (function(t) {
                    {
                        if ((1, i)) throw new TypeError("Generator is already executing.");
                        for (; s;)
                            try {
                                if (
                                    ((i = 1),
                                        r &&
                                        (a =
                                            2 & t[0] ?
                                            r.return :
                                            t[0] ?
                                            r.throw || ((a = r.return) && a.call(r), 0) :
                                            r.next) &&
                                        !(a = a.call(r, t[1])).done)
                                )
                                    return a;
                                switch (((r = 0), (t = a ? [2 & t[0], a.value] : t)[0])) {
                                    case 0:
                                    case 1:
                                        a = t;
                                        break;
                                    case 4:
                                        return s.label++, { value: t[1], done: !1 };
                                    case 5:
                                        s.label++, (r = t[1]), (t = [0]);
                                        continue;
                                    case 7:
                                        (t = s.ops.pop()), s.trys.pop();
                                        continue;
                                    default:
                                        if (!(a = 0 < (a = s.trys).length && a[a.length - 1]) &&
                                            (6 === t[0] || 2 === t[0])
                                        ) {
                                            s = 0;
                                            continue;
                                        }
                                        if (3 === t[0] && (!a || (t[1] > a[0] && t[1] < a[3]))) {
                                            s.label = t[1];
                                            break;
                                        }
                                        if (6 === t[0] && s.label < a[1]) {
                                            (s.label = a[1]), (a = t);
                                            break;
                                        }
                                        if (a && s.label < a[2]) {
                                            (s.label = a[2]), s.ops.push(t);
                                            break;
                                        }
                                        a[2] && s.ops.pop(), s.trys.pop();
                                        continue;
                                }
                                t = o.call(n, s);
                            } catch (e) {
                                (t = [6, e]), (r = 0);
                            } finally {
                                i = a = 0;
                            }
                        if (5 & t[0]) throw t[1];
                        return { value: t[0] ? t[1] : void 0, done: !0 };
                    }
                })([t, e]);
            };
        }
    };
Object.defineProperty(n, "__esModule", { value: !0 }),
    (n.loadString =
        n.loadDragonBone =
        n.loadDragonBoneAtlas =
        n.getResFromBundle =
        n.loadRes =
        n.loadRemote =
        n.loadRemoteSpritFrame =
        n.loadSpritFrame =
        n.loadLocalRes =
        n.loadAnimaClip =
        n.loadPrefab =
        void 0);
var r = e("index"),
    a = e("env");

function o(r, a) {
    return i(this, void 0, Promise, function() {
        var t, i, n;
        return l(this, function(e) {
            switch (e.label) {
                case 0:
                    return r ?
                        ((t = cc.resources),
                            (i = "resources"),
                            t.getInfoWithPath(r) ? [3, 2] :
                            ((i = "remote"),
                                (t = cc.assetManager.getBundle(i)) ? [3, 2] : [
                                    4,
                                    new Promise(function(n, o) {
                                        cc.assetManager.loadBundle(i, function(e, t) {
                                            e ? o(e) : n(t);
                                        });
                                    })
                                ])) : [2];
                case 1:
                    (t = e.sent()), (e.label = 2);
                case 2:
                    return [4, s(i, r, a)];
                case 3:
                    return (n = e.sent()) ? [2, n] : [
                        2,
                        new Promise(function(n, o) {
                            t.load(r, a, function(e, t) {
                                e ? o(e) : n(t);
                            });
                        })
                    ];
            }
        });
    });
}

function s(a, s, c) {
    return i(this, void 0, Promise, function() {
        var e, r;
        return l(this, function() {
            return s &&
                ((n = s), (o = c), (i = cc.assetManager.bundles), (e = t(a))) &&
                (r = cc.assetManager.assets.get(e)) ? [2, r] : [2, null];

            function t(e) {
                return i.has(e) && (e = i.get(e).getInfoWithPath(n, o)) ? (e.redirect ? t(e.redirect) : e.uuid) : null;
            }
            var n, o, i;
        });
    });
}
(n.loadPrefab = function(t) {
    return i(this, void 0, Promise, function() {
        return l(this, function(e) {
            switch (e.label) {
                case 0:
                    return [4, o(t, cc.Prefab)];
                case 1:
                    return [2, e.sent()];
            }
        });
    });
}),
(n.loadAnimaClip = function(t) {
    return i(this, void 0, Promise, function() {
        return l(this, function(e) {
            switch (e.label) {
                case 0:
                    return [4, o(t, cc.AnimationClip)];
                case 1:
                    return [2, e.sent()];
            }
        });
    });
}),
(n.loadLocalRes = function(e, t) {
    return new Promise(function(n, o) {
        cc.resources.load(e, t, function(e, t) {
            t ? n(t) : o("Local RES load failed, pls check out path!" + e);
        });
    });
}),
(n.loadSpritFrame = function(n, o) {
    return i(this, void 0, void 0, function() {
        var t;
        return l(this, function(e) {
            switch (e.label) {
                case 0:
                    return [4, r.ResUtil.loadRes(n, cc.SpriteFrame)];
                case 1:
                    return (t = e.sent()), o && (o.spriteFrame = t), [2, t];
            }
        });
    });
}),
(n.loadRemoteSpritFrame = function(n, o) {
    return i(this, void 0, void 0, function() {
        var t;
        return l(this, function(e) {
            switch (e.label) {
                case 0:
                    return [4, r.ResUtil.loadRemote(n, cc.SpriteFrame)];
                case 1:
                    return (t = e.sent()), (t = new cc.SpriteFrame(t)), o && (o.spriteFrame = t), [2, t];
            }
        });
    });
}),
(n.loadRemote = function(e) {
    return i(this, void 0, Promise, function() {
        return l(this, function() {
            return e ? [
                2,
                new Promise(function(n, o) {
                    cc.assetManager.loadRemote(a.env.network.resourceURL + e, function(e, t) {
                        n(t), e ? o(e) : n(t);
                    });
                })
            ] : [2];
        });
    });
}),
(n.loadRes = o),
(n.getResFromBundle = s),
(n.loadDragonBoneAtlas = function(e) {
    return i(this, void 0, Promise, function() {
        return l(this, function() {
            return [2, o(e, dragonBones.DragonBonesAtlasAsset)];
        });
    });
}),
(n.loadDragonBone = function(e) {
    return i(this, void 0, void 0, function() {
        return l(this, function() {
            return [2, o(e, dragonBones.DragonBonesAsset)];
        });
    });
}),
(n.loadString = function(t) {
    return i(this, void 0, Promise, function() {
        return l(this, function(e) {
            switch (e.label) {
                case 0:
                    return [4, o(t, cc.TextAsset)];
                case 1:
                    return [2, e.sent().text];
            }
        });
    });
});